<% add_decidim_page_title(t("decidim.admin.titles.participatory_process_groups")) %>
<% content_for :breadcrumb_context_menu do %>
  <div class="process-title-content-breadcrumb-container-right">
    <% if allowed_to? :create, :process_group %>
      <%= link_to [:new, :participatory_process_group], class: "button button__sm button__transparent process-title-content-breadcrumb-container-right-link" do %>
        <%= icon "add-line" %>
        <span>
          <%= t("actions.new_process_group", scope: "decidim.admin") %>
        </span>
      <% end %>
    <% end %>
  </div>
<% end %>

<%= admin_tabs(:admin_participatory_processes_menu).render %>

<div class="card">
  <div class="table-stacked">
    <table class="table-list">
      <thead>
        <tr>
          <th><%= t("models.participatory_process_group.fields.title", scope: "decidim.admin") %></th>
          <th><%= t("models.participatory_process_group.fields.actions", scope: "decidim.admin") %></th>
        </tr>
      </thead>
      <tbody>
        <% collection.each do |group| %>
          <tr>
            <td data-label="<%= t("models.participatory_process_group.fields.title", scope: "decidim.admin") %>">
              <% if group.promoted? %>
                <%= icon_with_tooltip "star-s-fill", t("models.assembly.fields.promoted", scope: "decidim.admin") %>
              <% end %>
              <% if allowed_to? :update, :process_group, process_group: group %>
                <%= link_to translated_attribute(group.title), [:edit, group] %>
              <% else %>
                <%= translated_attribute(group.title) %>
              <% end %>
            </td>
            <td class="table-list__actions" data-label="<%= t("models.participatory_process_group.fields.actions", scope: "decidim.admin") %>">
              <button type="button" data-controller="dropdown" data-target="actions-process-group-<%= group.id %>" aria-label="<%= t("decidim.admin.actions.actions_label", resource: translated_attribute(group.title)) %>">
                <%= icon "more-fill", class: "text-secondary" %>
              </button>

              <div class="inline-block relative">
                <ul id="actions-process-group-<%= group.id %>" class="dropdown dropdown__action" aria-hidden="true">
                  <% if allowed_to? :update, :process_group, process_group: group %>
                    <li class="dropdown__item">
                      <%= link_to [:edit, group], class: "dropdown__button" do %>
                        <%= icon "pencil-line" %> <%= t("actions.edit", scope: "decidim.admin") %>
                      <% end %>
                    </li>
                  <% end %>

                  <li class="dropdown__item">
                    <%= link_to decidim_participatory_processes.participatory_process_group_path(group, locale: current_locale), class: "dropdown__button", target: "_blank", data: { "external-link": false } do %>
                      <%= icon "eye-line" %> <%= t("actions.preview", scope: "decidim.admin") %>
                    <% end %>
                  </li>

                  <% if allowed_to? :destroy, :process_group, process_group: group %>
                    <li class="dropdown__item">
                      <%= link_to group, method: :delete, data: { confirm: t("actions.confirm_destroy", scope: "decidim.admin") }, class: "dropdown__button dropdown__button--danger" do %>
                        <%= icon "delete-bin-line" %> <%= t("actions.destroy", scope: "decidim.admin") %>
                      <% end %>
                    </li>
                  <% end %>
                </ul>
              </div>
            </td>
          </tr>
        <% end %>
      </tbody>
    </table>
  </div>
</div>
